package com.game.simplegame.creature;

import com.game.simplegame.world.World;

import java.io.FileInputStream;

/**
 * Created by Administrator on 2017-04-18.
 */
public class Creature {

    double energy = 100;
    ICreatureStatus creatureStatus;
    World theWorld;
    int x = 0;
    int y = 0;

    public Creature(ICreatureStatus initStatus,World world){
        creatureStatus = initStatus;
        theWorld  = world;
        initStatus.onActive(this,theWorld);
    }

    public void update(long dtSec,World world){
        creatureStatus.update(dtSec, this, world);
    }

    public void changeTo(ICreatureStatus status){
        if(creatureStatus.getClass().equals(status.getClass()))return;
        if(creatureStatus!=null){
            creatureStatus.onDisActive(this,theWorld);
        }
        creatureStatus = status;
        status.onActive(this,theWorld);
        System.out.println("change to " + status.getClass().getSimpleName());
    }

    public int getX(){
        return x;
    }

    public int getY(){
        return y;
    }

    public void move(int dx,int dy){
        x += dx;
        y += dy;
    }

    public void moveTo(int newX,int newY){
        x = newX;
        y = newY;
    }
    public void addEnergy(double val){
        energy += val;
    }
    public double getMoveEnergyCost(){
        return -0.01;
    }
    public double getSleepEnergyCost(){
        return -0.001;
    }
}
